package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.pojo.PageA;
import com.bjsxt.pojo.TreeA;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;


    @RequestMapping("/selectMenuController")
    public List<TreeA> selectMenuController(@RequestParam(defaultValue = "0") Integer id, HttpSession session){

        Admin admin = (Admin) session.getAttribute("admin");

        return menuService.selectMenuSice(admin.getAid(),id);
    }

    //分页查询
    @RequestMapping("/selectPagController")
    public PageA<Menu> selectPagController(Integer page,Integer rows){
        return menuService.selectPagMenu(page, rows);
    }

    //查询所有表单
    @RequestMapping("/selectMenuController2")
    public List<TreeA> selectMenuController2(@RequestParam(defaultValue = "0") Integer id){
        return menuService.selectMenuSice2(id);
    }

    //添加表单
    @RequestMapping("/insertMenuController")
    public Integer insertMenuController(Menu menu){
        return menuService.insertMenuSice(menu);
    }

    //修改表单
    @RequestMapping("/updateMenuController")
    public Integer updateMenuController(Menu menu){
        return menuService.updateMenuSice(menu);
    }

    //删除表单
    @RequestMapping("/deleteMenuController")
    public Integer deleteMenuController(Integer mid){
        return menuService.deleteMenuSice(mid);
    }

    //同部树查询
    @RequestMapping("/selectMenuController3")
    public List<TreeA> selectMenuController3(){
        return menuService.selectMenuSice3();
    }
}
